﻿@using KaytechSoftware.Cms.Common.Helpers
@model KaytechSoftware.Cms.App.Areas.Admin.Models.Base.GridModel

@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

    <table width="100%">
        <tr>
            <td colspan="2">
                @if (Model.Filters != null)
                {
                    { Html.RenderPartial("Partials/_Filters", Model, new ViewDataDictionary(new { area = "Admin"})); }
                }       
            </td>
            
        </tr>
        <tr>
            <td>
                <h2>@string.Format("List of {0}", Model.ControllerName)</h2>
            </td>
            <td style="text-align: right;">
                <a class="hoverable" href="@Url.Action("Add", Model.ControllerName, new { area = "Admin" })">Add</a>
            </td>
        </tr>
    </table>

<table width="100%">
    <thead>
        <tr>
            @foreach (var column in Model.Columns)
            {
                <th class="grid-header">
                    @column.NameResourceKey
                </th>
            }
            <th>
                Up
            </th>
            <th>
                Down
            </th>
            <th>
                Edit
            </th>
            <th>
                Delete
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var row in Model.Rows)
        {
            <tr>
                @foreach (var cell in row.Cells)
                {
                    <td class="grid-cell @(cell.IsImageCell ? "image-cell" : string.Empty)">
                        @if (cell.IsImageCell)
                        {
                            if (cell.IsEditLink)
                            {
                                if (cell.Image != null)
                                {
                                    <a href="@Url.Action("Edit", Model.ControllerName, new {area = "Admin", id = row.Id})">
                                        <img src="@PathHelper.PhotoThumbPathForWeb(cell.Image.AlbumId, cell.Image.PhotoId, cell.Image.Version)" alt=""/>
                                    </a>
                                }
                                else
                                {
                                    <a href="@Url.Action("Edit", Model.ControllerName, new {area = "Admin", id = row.Id})">
                                        <img width="92" height="68" style="float: left;" src="~/Content/images/photo.jpg" />
                                    </a>
                                }
                            }
                            else
                            {
                                if (cell.Image != null)
                                {
                                    <img src="@PathHelper.PhotoThumbPathForWeb(cell.Image.AlbumId, cell.Image.PhotoId, cell.Image.Version)" alt=""/>
                                }
                                else
                                {
                                    <img width="92" height="68" style="float: left;" src="~/Content/images/photo.jpg" />
                                }
                            }
                            
                        }
                        else if (cell.IsActionLink)
                        {
                            <a class="hoverable" href="@Url.Action(cell.Action, Model.ControllerName, new {area = "Admin", id = row.Id})">@cell.Text</a>
                        }
                        else
                        {
                            @cell.Text
                        }
                    </td>
                }
                <td>
                    <a class="hoverable" href="@Url.Action("Up", Model.ControllerName, new { area = "Admin", id = row.Id })">Up</a>
                </td>
                <td>
                    <a class="hoverable" href="@Url.Action("Down", Model.ControllerName, new { area = "Admin", id = row.Id })">Down</a>
                </td>
                <td>
                    <a class="hoverable" href="@Url.Action("Edit", Model.ControllerName, new { area = "Admin", id = row.Id })">Edit</a>
                </td>
                <td>
                    <a class="hoverable" href="@Url.Action("Delete", Model.ControllerName, new { area = "Admin", id = row.Id })">Delete</a>
                </td>
            </tr>
        }
    </tbody>
</table>